﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using Single_SignOn.Models;

namespace Single_SignOn.ResX
{
    public sealed class ResourceTools
    {

        #region Resources

       public static string GetResource(string ResourceName, string ResourceKey)
        {
            string r = HttpContext.GetGlobalResourceObject(ResourceName, ResourceKey) as string;
            if (r == null)
                return ResourceKey;
            return r;
        }

        #endregion
    }

    public sealed class WebConfig
    {
        public static String Cookies = (String)System.Configuration.ConfigurationManager.AppSettings["cookies"];

        public static Boolean ActiveDirectiry = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["activedirectiry"]);

        public static String Encryptkey = (String)(System.Configuration.ConfigurationManager.AppSettings["zencryptkey"]);

        public static String EncryptValue = (String)(System.Configuration.ConfigurationManager.AppSettings["zencryptvalue"]);

        public static string ApplNoVersion(string applno)
        {
            return (String)(System.Configuration.ConfigurationManager.AppSettings[applno + "_version"]); ;
        }

        public static string ApplNoLastUpdate(string applno)
        {
            return (String)(System.Configuration.ConfigurationManager.AppSettings[applno + "_last_updated"]); ;
        }
    }

    public sealed class SessionPool
    {
        private static DataAccess.SingleSignOn.AuthenConnection oAuth;

        public static void getSession(string username)
        {
            oAuth = new DataAccess.SingleSignOn.AuthenConnection();

            DataTable dtUserData = oAuth.getUserData(username);
            UserProfile oUserProfile;//= new UserProfile();
            if (dtUserData != null)
                if (dtUserData.Rows.Count > 0)
                {
                    System.Web.HttpContext.Current.Session.Remove("UserInfo");
                    oUserProfile = new UserProfile();
                    oUserProfile.Description = (System.DBNull.Value == dtUserData.Rows[0]["DESCRIPTION"]) ? "" : (string)dtUserData.Rows[0]["DESCRIPTION"];
                    oUserProfile.GroupDescription = (System.DBNull.Value == dtUserData.Rows[0]["GROUPDESC"]) ? "" : (string)dtUserData.Rows[0]["GROUPDESC"];
                    oUserProfile.EmployeeNo = (System.DBNull.Value == dtUserData.Rows[0]["EMPID"]) ? "" : (string)dtUserData.Rows[0]["EMPID"];
                    oUserProfile.Username = (System.DBNull.Value == dtUserData.Rows[0]["EMPNO"]) ? "" : (string)dtUserData.Rows[0]["EMPNO"];
                    oUserProfile.FullName = (System.DBNull.Value == dtUserData.Rows[0]["EMPNAME"]) ? "" : (string)dtUserData.Rows[0]["EMPNAME"];
                    oUserProfile.Password = (System.DBNull.Value == dtUserData.Rows[0]["PASSWORD"]) ? "" : (string)dtUserData.Rows[0]["PASSWORD"];
                    oUserProfile.GroupNo = (System.DBNull.Value == dtUserData.Rows[0]["GROUPNO"]) ? "" : (string)dtUserData.Rows[0]["GROUPNO"];
                    oUserProfile.Division = (System.DBNull.Value == dtUserData.Rows[0]["DIVISION"]) ? "" : (string)dtUserData.Rows[0]["DIVISION"];
                    oUserProfile.Store = (System.DBNull.Value == dtUserData.Rows[0]["STORENO"]) ? "" : (string)dtUserData.Rows[0]["STORENO"];
                    oUserProfile.Tel = (System.DBNull.Value == dtUserData.Rows[0]["TEL"]) ? "" : (string)dtUserData.Rows[0]["TEL"];
                    oUserProfile.Email = (System.DBNull.Value == dtUserData.Rows[0]["EMAIL"]) ? "" : (string)dtUserData.Rows[0]["EMAIL"];
                    oUserProfile.Status = (System.DBNull.Value == dtUserData.Rows[0]["STATUS"]) ? "" : (string)dtUserData.Rows[0]["STATUS"];
                    oUserProfile.ApplNo = (System.DBNull.Value == dtUserData.Rows[0]["APPLNO"]) ? "" : (string)dtUserData.Rows[0]["APPLNO"];
                    oUserProfile.ProfileLevel = (System.DBNull.Value == dtUserData.Rows[0]["PROFILELEVEL"]) ? "" : (string)dtUserData.Rows[0]["PROFILELEVEL"];
                    oUserProfile.Language = (System.DBNull.Value == dtUserData.Rows[0]["LANG"]) ? "" : (string)dtUserData.Rows[0]["LANG"];
                    System.Web.HttpContext.Current.Session["UserInfo"] = oUserProfile;
                }
        }

    }


}